home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0047_Filedate and Time.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-03  |  2KB  |  44 lines

  1. {
  2. ET>How can I change the file's date and time without opening that file??
  3. ET>I appreciate (some) example source code, so I can look how it is done.
  4. ET>Thanks.
  5.  
  6.  In order to change a files date/timestamp you'll have open the file
  7.  whether you use the TP SetFTime routine or use Int 21h Function 5701
  8.  BUT by Opening it for reading you can change it to whatever you want.
  9.  If you open it for writing then the TimeStamp will automatically be
  10.  changed to whatever the time was when you closed it.
  11.  
  12.  Here's a little demo that changes the files timestamp to whatever the
  13.  current time is:
  14.  (NOTE this does not test for existance of the file before settingthe time.)}
  15.  
  16. {*******************************************************************}
  17. PROGRAM SetFileDateAndTimeDemo; { Jan 8/93, Greg Estabrooks.        }
  18. USES CRT,                       { IMPORT Clrscr,Writeln.            }
  19.      DOS;                       { IMPORT SetFTime,PackTime,DateTime,}
  20.                                 { GetTime,GetDate.                  }
  21. VAR
  22.    Hour,Min,Sec,Sec100 :WORD;   { Variables to hold current time.   }
  23.    Year,Mon,Day,DayoW  :WORD;   { Variables to hold current date.   }
  24.    F2Change :FILE;              { Handle for file to change.        }
  25.    NewTime  :LONGINT;           { Longint Holding new Date/Time.    }
  26.    FTime    :DateTime;          { For use with packtime.            }
  27. BEGIN
  28.   Clrscr;                       { Clear the screen.                 }
  29.   GetTime(Hour,Min,Sec,Sec100); { Get Current System Time.          }
  30.   GetDate(Year,Mon,Day,DayoW);  { Get Current System Date.          }
  31.   FTime.Year := Year;           { Assign new year.                  }
  32.   FTime.Month:= Mon;            { Assign new month.                 }
  33.   FTime.Day := Day;             { Assign New Day.                   }
  34.   FTime.Hour:= Hour;            { Assign New hour.                  }
  35.   FTime.Min := Min;             { Assign New Minute.                }
  36.   FTime.Sec := Sec;             { Assign New Seconds.               }
  37.   PackTime(FTime,NewTime);      { Now covert Time/Date to a longint.}
  38.   Assign(F2Change,ParamStr(1)); { Assign file handle to file to change.}
  39.   Reset(F2Change);              { Open file for reading.            }
  40.   SetFTime(F2Change,NewTime);   { Now change to our time.           }
  41.   Close(F2Change);              { Close File.                       }
  42. END.{SetFileDateAndTimeDemo}
  43. {*******************************************************************}
  44.